//Code from : exod40
//Wednesday, November 25 2009
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class MazeMaker
{
public:
	int longestPath(vector <string> maze, int startRow, int startCol, vector <int> moveRow, vector <int> moveCol)
	{
		return solve(maze, startRow, startCol, moveRow, moveCol);
	}
	int solve(vector<string> a, int x, int y, vector<int> dx, vector<int> dy)
	{
		int ret = 0;
		memset(used, -1, sizeof(used));
		q.push(make_pair(x,y));
		used[x][y] = 0;
		while(!q.empty())
		{
			x = q.front().first;
			y = q.front().second;
			q.pop();

			for(int i=0; i<dx.size(); i++)
			{
				int xx = x + dx[i];
				int yy = y + dy[i];

				if(xx>=0 && xx<a.size() && yy>=0 && yy<a[0].size() && used[xx][yy]==-1 && a[xx][yy]=='.')
				{
					used[xx][yy] = used[x][y] + 1;
					q.push(make_pair(xx,yy));
				}
			}
		}
		for(int i=0; i<a.size(); i++)
			for(int j=0; j<a[0].size(); j++)
			{
				if(a[i][j] == '.')
				{
					if(used[i][j] == -1) ret = -1;	//It means this area is not reachable.
					if(ret != -1 && used[i][j] > ret)
						ret = used[i][j];
				}
			}
		return ret;
	}
	queue<pair<int, int> > q;
	int used[64][64];
};
